import Base from 'models/base';
import moment from 'moment';

import SystemUtil from 'utils/systemUtil';

export default class CircleZoneLog extends Base {
  constructor(log) {
    super();

    this.id = SystemUtil.getId();
    this.logId = log.manliSpaceLogId;
    this.spaceId = log.spaceId;
    this.unionid = log.reviewerUnionid;
    this.name = log.reviewerNickname;
    this.headimgurl = log.reviewerHeadimgurl;
    this.timeDistance = log.timeDistance;
    this.content = log.reviewContent;
    this.createTime = moment(log.createTime).valueOf();

    let replyUnionid = log.respondentUnionid;
    if (SystemUtil.isEmpty(replyUnionid)) {
      this.replyUnionid = null;
      this.replyName = null;
    } else {
      this.replyUnionid = replyUnionid;
      this.replyName = log.respondentNickname;
    }
    this.resetCircleLogStatusData(log);
  }

  resetCircleLogStatusData(log) {
    this.isPraise = log.likeCountId !== null;

    let praiseCount = log.likeCount;
    if (SystemUtil.isEmpty(praiseCount)) {
      praiseCount = 0;
    }
    this.praiseCount = praiseCount;
  }
}